package hash.lc02;

/**
 * @Author Stringzhua
 * @Date 2024/3/26 18:29
 * description:测试
 */
public class Test02 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        int total = l1.val + l2.val;
        int next1 = total / 10;
        ListNode result = new ListNode(total % 10);
        if (l1.next != null || l2.next != null || next1 != 0) {
            if (l1.next != null) {
                l1 = l1.next;
            } else {
                l1 = new ListNode(0);
            }
            if (l2.next != null) {
                l2 = l2.next;
            } else {
                l2 = new ListNode(0);
            }
            l1.val = l1.val + next1;
            result.next = addTwoNumbers(l1, l2);
        }
        return result;
    }

    public static void main(String[] args) {

    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}

